package com.itboye.lottery.popupwindow;

import android.content.Context;
import android.widget.AdapterView;
import android.widget.PopupWindow;

import com.itboye.lottery.R;
import com.itboye.lottery.adapter.MyLotteryPopAdapter;
import com.itboye.lottery.base.BasePopupWindow;
import com.itboye.lottery.view.BallGridView;

public class MyLotteryMenuPopUpWindow extends BasePopupWindow {

    private BallGridView gridview;
    private String[] names,types;
    private Context mContext;
    private int pager = 0;
    private AdapterView.OnItemClickListener itemClicklistener;
    private PopupWindow.OnDismissListener dismissListener;
    MyLotteryPopAdapter adapter;
    public MyLotteryMenuPopUpWindow(Context context) {
        super(context);
        init();
    }


    /**
     * 直接把所有的监听都抛出去 在外面实现
     * @param context
     * @param pager
     * @param itemClicklistener
     * @param dismissListener
     */
    public MyLotteryMenuPopUpWindow(Context context,String[] names,String[] types, int pager,
                                    AdapterView.OnItemClickListener itemClicklistener,
                                    PopupWindow.OnDismissListener dismissListener) {
        super(context);
        mContext = context;
        this.names = names;
        this.types = types;
        this.pager = pager;
        this.itemClicklistener = itemClicklistener;
        this.dismissListener = dismissListener;
        init();
    }
    @Override
    protected boolean allowBackgroundTranslucent() {
        return true;
    }

    @Override
    protected int setPopWindowAnimationStyle() {
        return -1;
    }

    void init() {
        // 设置SelectPicPopupWindow弹出窗体可点击
        setFocusable(true);
        setOutsideTouchable(true);
        setContentView(R.layout.fragment_hemai_popuwindow);
        gridview = findViewById(R.id.gridview);
        adapter = new MyLotteryPopAdapter(mContext,names,types,pager);
        gridview.setAdapter(adapter);
        gridview.setOnItemClickListener(itemClicklistener);
        setOnDismissListener(dismissListener);
        update();
    }

    public void notifyDataSetChanged(){
        adapter.notifyDataSetChanged();
    }


    public void setPager(int pager){
        this.pager = pager;
        adapter.setPager(pager);
    }
}
